<!--
  ~ Copyright 2008-2019 the original author or authors.
  ~
  ~ Licensed under the Apache License, Version 2.0.
  ~ See `LICENSE` in the project root for license information.
  -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Banner Image</title>
</head>
<body>
    <input type="file" accept="image/*">
    <button type="button" onclick="upload()">上传</button>

    <script type="application/javascript">
        function upload() {
            const fileField = document.querySelector('input[type="file"]');

            const formData = new FormData();
            formData.append('file', fileField.files[0]);
            formData.append('encrypt', 'false');

            // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
            // https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API/Using_Fetch
            fetch('/ij-mgmt/system/upload-file/upload', {
                method: 'POST',
                body: formData
            }).then(function(rsp) {
                if (rsp.ok) {
                    return rsp.json();
                }
                throw new Error(`Request rejected with status ${rsp.status}.`);
            }).then(function(data) {
                console.log('Success', data);
            }).catch(function(err) {
                console.error(err);
            });
        }
    </script>
</body>
</html>
